package com.demo2do.fms.admin.dao.data;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Execute;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.data.cost.TyreFee;

/**
 * 
 * @author Wy
 *
 */
@Dao("hibernate")
public interface TyreFeeDao {
    
    /**
     * 
     * @param orgIds
     * @return
     */
    @Query("SELECT count(*) FROM TyreFee fee WHERE fee.organization.id in (:orgIds)")
    public int count(@Variable("orgIds") List<Long> orgIds);
    
    /**
     * 
     * @param orgIds
     * @param beginIndex
     * @param maxResult
     * @return
     */
     @Limit
     @Query("FROM TyreFee fee WHERE fee.organization.id IN (:orgIds) ORDER BY fee.organization.name ASC")
     public List<TyreFee> list(@Variable("orgIds") List<Long> orgIds, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    
    /**
     * list tyre_fee by company_id and power_type_id
     * 
     * @param orgId
     * @param powerTypeId
     * @return
     */
    @Query("FROM TyreFee WHERE organization.id = :orgId AND vehicleFeature.id = :powerTypeId AND disabled = false")
    public List<TyreFee> list(@Variable("orgId") Long orgId, @Variable("powerTypeId") Long powerTypeId);
    
    
    /**
     * update list of tyre_fee 
     * 
     * @param orgId
     * @param powerTypeId
     */
    @Execute("UPDATE TyreFee SET disabled = true WHERE organization.id = :orgId AND vehicleFeature.id = :powerTypeId AND disabled = false")
    public void disable(@Variable("orgId") Long orgId, @Variable("powerTypeId") Long powerTypeId);

}
